package com.xiaotu.spider.guduo.pipeline;

import java.util.List;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.CompanyBasicinfoModel;
import com.xiaotu.common.model.CompanyTvWorksModel;
import com.xiaotu.common.model.MaoYanMovieBasicInfoModel;
import com.xiaotu.common.model.StarBasicinfoModel;
import com.xiaotu.common.model.StarTvWorksModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/***
 * 骨朵网大剧基本信息 （来源猫眼）
 * @author 
 *
 */
@Component("GuDuoNetMovieBasicInfoPipeline")
public class GuDuoNetMovieBasicInfoPipeline extends APipeline {

	@Override
	protected void doProcess(ResultItems resultItems, Task task) {
		MaoYanMovieBasicInfoModel obj = resultItems.get(MaoYanMovieBasicInfoModel.class.getName());
		if(null != obj){
			String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.NETMOVIE_INFO_SUPPLEMENT_YYYYMMDD);
			cacheHandler.hSet(key, obj.getId(), obj);
	        cacheHandler.setCacheTimeout(key);
		}
		
		List<StarTvWorksModel> list = resultItems.get(StarTvWorksModel.class.getName());
        if(null != list && list.size()>0){
        	String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.STAR_WORKS_SUPPLEMENT_YYYYMMDD);
        	for(StarTvWorksModel model : list){
        		cacheHandler.hSet(key, model.getStar_dataid()+"_"+model.getId(), model);
        	}
        	cacheHandler.setCacheTimeout(key);
        }
        
        List<CompanyTvWorksModel> companyWorkslist = resultItems.get(CompanyTvWorksModel.class.getName());
        if(null != companyWorkslist && companyWorkslist.size()>0){
        	String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.COMPANY_WORKS_SUPPLEMENT_YYYYMMDD);
        	for(CompanyTvWorksModel model : companyWorkslist){
        		cacheHandler.hSet(key, model.getCompany_dataid()+"_"+model.getId(), model);
        	}
        	cacheHandler.setCacheTimeout(key);
        }
	}
	
}
